package main

import (
	"fmt"
)

//效率太差，时间太长
func longestPalindrome(s string) string {
	count := make(map[string]int) //声明，初始化一个map
	var tempStr []byte
	result := ""
	maxSize := 0
	//找出所有首位字符相同的串(回文数的判断)
	//存入hashmap
	result = string(s[0])
	for i := 0; i < len(s)-1; i++ {

		tempStr = nil
		tempStr = append(tempStr, byte(s[i]))

		for j := i + 1; j < len(s); j++ {
			tempStr = append(tempStr, byte(s[j]))
			if s[j] == s[i] {
				count[string(tempStr)] = (j - i + 1)
				continue
			} else {
				result = string(s[0])
			}

		}

	}

	//找到回文
	for char, _ := range count {
		j := len(char) - 1
		for i := 0; i < len(char); i++ {

			if i > j {
				break
			}
			if char[i] != char[j] {
				delete(count, char)
				break
			}
			j--

		}

	}

	fmt.Println(count)
	for char, size := range count {
		if size > maxSize {
			maxSize = size
			result = string(char)
		}

	}

	//判断最长的一个回文子串

	return result

}

func main() {
	inputStr := "aba"
	outputStr := longestPalindrome(inputStr)
	fmt.Println(outputStr)
}
